package ie.timalb.chess.main.core.grid;

public class Grid {
	private GridDimensions _dimensions;
	private Cells _cells;
	
	public Grid(int xDimension, int yDimension) {
		setDimensions(new GridDimensions(xDimension, yDimension));
		populateGrid ();
	}	
	
	public Grid(GridDimensions dimensions) {
		setDimensions(dimensions);
		populateGrid ();
	}
	
	private void populateGrid (){
		setCells(new Cells());
	}

	private Cells getCells() {
		return _cells;
	}
	private void setCells(Cells cells) {
		this._cells = cells;
	}

	private GridDimensions getDimensions() {
		return _dimensions;
	}

	private void setDimensions(GridDimensions _dimensions) {
		this._dimensions = _dimensions;
	}

	public CellIterator getIterator() {
		Cell firstCell = getCell(getDimensions().getFirstLocation());
		Cell lastCell = getCell(getDimensions().getLastLocation());
		CellIteratorStrategy itStrategy = new GridDefaultIterationStrategy (firstCell, lastCell); 
		return this.getCells().getIterator (itStrategy);
	}

	private Cell getCell(CellLocation firstLocation) {
		return getCells().getCell(firstLocation);
	}
}
